/*
 * @Author: chunlai
 * @Date: 2025-07-17 16:15:56
 * @LastEditTime: 2025-09-05 08:41:34
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\mixins\tbrbbr.js
 * @Description: 投保人+被保人
 */
import { mapGetters } from "vuex";
export const tbrBbrMixin = {
  data() {
    return {
      BMIvalue: null,
      BMIres: "正常",
      taxIdentDemo: {
        crsSurName: "", // "姓",
        crsName: "", //"名",
        crsHomeNativePlace: "", // "现居地址(中文)国",
        crsHomeProvince: "", //"现居地址(中文)省",
        crsHomeCity: "", //"现居地址(中文)市",
        crsHomeCounty: "", //"现居地址(中文)区/县",
        crsHomeAddress: "", //"现居地址(中文)详细地址",
        crsEnHomeNativePlace: "", // "现居地址(英文或拼音)国",
        crsEnHomeAddress: "", //"现居地址(英文或拼音)详细地址",
        crsBirthNativePlace: "", //"出生地(中文)国",
        crsBirthProvince: "", //"出生地(中文)省",
        crsBirthCity: "", //"出生地(中文)市",
        crsBirthCounty: "", //"出生地(中文)区/县",
        crsBirthAddress: "", //"出生地(中文)出生地详细地址",
        crsEnBirthNativePlace: "", // "出生地(英文或拼音)国",
        crsEnBirthAddress: "", //"出生地(英文或拼音)出生地详细地址",
        taxIdentDetail: [
          // {
          //   "crsTaxPlace": "税收居民国（地区）",
          //   "crsTaxNo": "纳税人识别号",
          //   "noTaxNoReason": "无法提供居民国（地区）纳税人识别号原因编码,1-居民国（地区）不发放纳税人识别号,2-账户持有人未能取得纳税人识别号,如果选2需要填写原因",
          //   "noTaxNoReasonDetail": "无法提供居民国（地区）纳税人识别号详细原因"
          // }
        ],
      },
    };
  },
  computed: {
    ...mapGetters({
      hasResidentFile: "page/hasResidentFile",
      adultAgeStandard: "dictionary/adultAgeStandard",
    }),
  },
  methods: {
    testBMI(type) {
      // 未成年人不校验BMI
      if (!this.ageVal || Number(this.ageVal) < this.adultAgeStandard) {
        this.BMIvalue = "";
        this.BMIres = "";
        return;
      }
      const weight = Number(this.userInfo.weight);
      const height = Number(this.userInfo.height);
      if (weight && height) {
        // 计算BMI值
        const heightInMeter = height / 100; // 身高转为米
        const bimVal = weight / (heightInMeter * heightInMeter);
        // 格式化BMI值
        try {
          this.BMIvalue = bimVal.toFixed(2);
        } catch (e) {
          console.error("BMI计算结果格式化失败", e);
          return;
        }
        // 定义BMI范围和描述
        const bmiRanges = [
          { max: 18.4, desc: "偏瘦" },
          { min: 18.5, max: 23.9, desc: "正常" },
          { min: 24, max: 27.9, desc: "过重" },
          { min: 28, desc: "肥胖" },
        ];
        // 判断BMI描述
        let ttDesc = "未知";
        for (const range of bmiRanges) {
          if (range.max !== undefined && bimVal <= range.max) {
            ttDesc = range.desc;
            break;
          } else if (range.min !== undefined && bimVal >= range.min) {
            ttDesc = range.desc;
          }
        }
        this.BMIres = ttDesc;
        if (bimVal < 10 || bimVal > 40) {
          this.$msAlert(
            `${
              this.userType || ""
            }身高体重不在正常BMI范围【BMI=体重(公斤)/身高(米)^2】，提交后可能会进入人工核保，请确认`
          );
        }
      }
    },
    testIncom() {
      if (this.userInfo.income >= 100 || this.userInfo.income < 0) {
        this.$msAlert(
          `${this.userType || ""}年收入：${
            this.userInfo.income
          }（万元），提交后可能会进入人工核保，请确认`
        );
      }
    },
    openCrsIdType() {
      if (this.hasResidentFile) {
        if (!this.userInfo.name) {
          return this.$toast("请输入姓名");
        }
        let dataObj = JSON.parse(JSON.stringify(this.taxIdentDemo)),
          data2 = JSON.parse(JSON.stringify(this.userInfo.taxIdentInfo));
        Object.assign(dataObj, data2);
        this.changeData({
          taxIdentInfo: dataObj,
        });
        this.showFile = true;
      } else {
        // 无税收文件，至空
        this.changeData({
          taxIdentInfo: {},
        });
        this.showPopAction("picker", "crsIdType", this.crsIdTypeList);
      }
    },
  },
};
